﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: StoredProcedureNamedParameter.cs
//
//  Description: Class represents a parameter for the StoredProcedureQuery.
// 
//--------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Text;

namespace Chili.Opf3.Query.StoredProcedures
{
	/// <summary>
	/// This class represents a parameter for the <see cref="StoredProcedureQuery">StoredProcedureQuery</see>
	/// Class.
	/// </summary>
	public sealed class StoredProcedureNamedParameter
	{
		private string _name;
		private object _value;
		private Type _type;

		/// <summary>
		/// Creates a new instance of the <see cref="StoredProcedureNamedParameter">StoredProcedureNamedParameter</see>
		/// Class.
		/// </summary>
		/// <param name="name">The name of the parameter; without the storage specific prefix!</param>
		/// <param name="value">The value of the parameter.</param>
		public StoredProcedureNamedParameter(string name, object value)
		{
			if (name == null)
				throw new ArgumentNullException("name");
			_name = name;
			_value = value;
		}

		/// <summary>
		/// Creates a new instance of the <see cref="StoredProcedureNamedParameter">StoredProcedureNamedParameter</see>
		/// Class.
		/// </summary>
		/// <param name="name">The name of the parameter; without the storage specific prefix!</param>
		/// <param name="value">The value of the parameter.</param>
		/// <param name="type">The type of the parameter's value.</param>
		public StoredProcedureNamedParameter(string name, object value, Type type)
			: this(name, value)
		{
			if (type == null)
				throw new ArgumentNullException("type");
			_type = type;
		}

		/// <summary>
		/// Gets the name of the parameter.
		/// </summary>
		public string Name
		{
			get { return _name; }
		}

		/// <summary>
		/// Gets the value of the parameter.
		/// </summary>
		public object Value
		{
			get { return _value; }
		}

		/// <summary>
		/// Gets the type of the parameter's value.
		/// </summary>
		public Type Type
		{
			get
			{
				if (_type != null)
					return _type;
				if (_value != null)
					return _value.GetType();
				return typeof(object);
			}
		}
	}
}
